/**   
 * <p>Title: YouGetMoneyMeRepayController.java</p>
 * @Package com.daisuxia.web.controller 
 * <p>Description: 你借钱我来还活动controller</p> 
 * <p>Company:贷速侠</p>
 * @author lixingxing
 * @since 2017年3月13日 下午4:27:18 
 * @version V1.0   
 */
package com.daisuxia.web.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.daisuxia.web.pojo.YouGetMoneyMeRepayInfo;
import com.daisuxia.web.service.IYouGetMoneyMeRepayService;
import com.daisuxia.web.util.JedisDataClient;

import redis.clients.jedis.JedisCluster;

/** 
 * <p>Description: 你借钱我来还活动controller</p> 
 * <p>Company:贷速侠</p>
 * @author lixingxing
 * @version V1.0 
 */
@Controller
@RequestMapping("ygmmr")
public class YouGetMoneyMeRepayController extends BaseController
{
        private static final Logger logger=LoggerFactory.getLogger(YouGetMoneyMeRepayController.class);
        
        @Resource
        private IYouGetMoneyMeRepayService youGetMoneyMeRepayService;
        
        @Resource
        private JedisCluster jedisCluster;
        
        @RequestMapping("/index")
        public String initPage(HttpServletRequest request, HttpServletResponse response){
            String deviceId=request.getParameter("deviceId");
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2=new SimpleDateFormat("MM月d日");
            Date nowdate=new Date();
            if(deviceId!=null&&!"".equals(deviceId)){
                List<String> clickdevices=null;
                String cachekey="youGetMoneyMeRepayActivePageClickNum_"+sdf.format(nowdate);
                try
                {
                    clickdevices=jedisCluster.lrange(cachekey, 0, -1);
                    if(clickdevices==null||clickdevices.size()==0){
                        jedisCluster.lpush(cachekey, deviceId);
                    }else{
                        if(!clickdevices.contains(deviceId)){
                            jedisCluster.lpush(cachekey, deviceId);
                        }
                    }
                    
                }
                catch (Exception e)
                {
                  logger.error("存取你来借我来还活动页面点击数据异常...",e);
                }
            }
            Calendar calendar=Calendar.getInstance();
            calendar.setTime(nowdate);
            calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
            request.setAttribute("nowdate", sdf2.format(calendar.getTime()));
            List<YouGetMoneyMeRepayInfo> nowlist=youGetMoneyMeRepayService.selectByList(sdf.format(calendar.getTime()));
            if(nowlist==null||nowlist.size()==0){
                logger.info("查询当天的你来借我来还活动无数据....");
            }
            request.setAttribute("nowlist", nowlist);
            calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
            request.setAttribute("beforelist_onedate", sdf2.format(calendar.getTime()));
            List<YouGetMoneyMeRepayInfo> beforelist_one=youGetMoneyMeRepayService.selectByList(sdf.format(calendar.getTime()));
            if(beforelist_one==null||beforelist_one.size()==0){
                logger.info("查询前一天的你来借我来还活动无数据....");
            }
            request.setAttribute("beforelist_one", beforelist_one);
            calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
            request.setAttribute("beforelist_twodate", sdf2.format(calendar.getTime()));
            List<YouGetMoneyMeRepayInfo> beforelist_two=youGetMoneyMeRepayService.selectByList(sdf.format(calendar.getTime()));
            if(beforelist_two==null||beforelist_two.size()==0){
                logger.info("查询前两天的你来借我来还活动无数据....");
            }
            request.setAttribute("beforelist_two", beforelist_two);
            return "reward/ygmmr_active";
        }
    
}
